<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
<!--      <el-form-item label="开始时间" prop="startDate">-->
<!--        <el-date-picker-->
<!--          clearable-->
<!--          v-model="queryParams.startDate"-->
<!--          type="date"-->
<!--          value-format="YYYY-MM-DD"-->
<!--          placeholder="请选择开始时间"-->
<!--        >-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="结束时间" prop="endDate">-->
<!--        <el-date-picker-->
<!--          clearable-->
<!--          v-model="queryParams.endDate"-->
<!--          type="date"-->
<!--          value-format="YYYY-MM-DD"-->
<!--          placeholder="请选择结束时间"-->
<!--        >-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
      <!-- <el-form-item label="所属军区" prop="theirMilitary">
        <el-select
          v-model="queryParams.theirMilitary"
          placeholder="请选择所属军区"
        >
          <el-option
            v-for="dict in belong_military_region"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
            @change="handleQuery"
          ></el-option>
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="用户昵称" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入用户昵称"
          clearable
          @keyup.enter="handleQuery"
          style="width: 150px"
        />
      </el-form-item> -->
      <!-- <el-form-item label="销售主管" prop="salesDirector">
        <el-input
          v-model="queryParams.salesDirector"
          placeholder="请输入主管名称"
          clearable
          @keyup.enter="handleQuery"
          style="width: 150px"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="Download"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['business:hairTriggerEvent:export']"-->
<!--          >导出</el-button-->
<!--        >-->
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="24" class="mb8">-->
<!--      <el-col :span="3"> 总访问人数:{{ allVisiteData.visitSum }} </el-col>-->
<!--      <el-col :span="3"> 总注册人数:{{ allVisiteData.registerSum }} </el-col>-->
<!--      <el-col :span="3"> 近30天平均日活:{{ allVisiteData.svgVisit }} </el-col>-->
<!--      <el-col :span="3">-->
<!--        近30天平均预约率:{{ allVisiteData.svgRegisterRate }}%-->
<!--      </el-col>-->
<!--      <el-col :span="3">-->
<!--        近30天注册到店率:{{ allVisiteData.signUpRate}}%-->
<!--      </el-col>-->
<!--      <right-toolbar-->
<!--        v-model:showSearch="showSearch"-->
<!--        @queryTable="getList"-->
<!--      ></right-toolbar>-->
<!--    </el-row>-->

<!--    <el-table-->
<!--      v-loading="loading"-->
<!--      :data="postShareList"-->
<!--      @selection-change="handleSelectionChange"-->
<!--    >-->
<!--      <el-table-column label="访问人数" align="center" prop="visitUv" />-->
<!--      <el-table-column label="新客访问人数" align="center" prop="visitUvNew" />-->
<!--    </el-table>-->
    <el-descriptions v-loading="loading" direction="vertical" :column="6" border>
      <el-descriptions-item label="活动页打开总人数">{{ allVisiteData.activityOpenPersonNum}}</el-descriptions-item>
      <el-descriptions-item label="活动页分享总次数">{{ allVisiteData.activityShareNum }}</el-descriptions-item>
      <el-descriptions-item label="活动页分享总人数">{{ allVisiteData.activitySharePersonNum }}</el-descriptions-item>
      <el-descriptions-item label="点击“参与”总次数">{{ allVisiteData.participationNum }}</el-descriptions-item>
      <el-descriptions-item label="点击“参与”总人数">{{ allVisiteData.participationPersonNum }}</el-descriptions-item>
    </el-descriptions>

<!--    <pagination-->
<!--      v-show="total > 0"-->
<!--      :total="total"-->
<!--      v-model:page="queryParams.pageNum"-->
<!--      v-model:limit="queryParams.pageSize"-->
<!--      @pagination="getList"-->
<!--    />-->
  </div>
</template>

<script setup name="HairTriggerEvent">
import {
  getBuildStatistics

} from "@/api/business/operation";

const { proxy } = getCurrentInstance();
const { belong_military_region } = proxy.useDict("belong_military_region");

const postShareList = ref([]);
const allVisiteData = ref({});
const open = ref(false);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 15,
    userId: undefined,
    type: undefined,
    startDate: undefined,
    endDate: undefined,
    nickName: undefined,
    salesDirector: undefined,
    eventValue: undefined,
    theirMilitary: undefined,
  },
  rules: {
    id: [{ required: true, message: "主键id不能为空", trigger: "blur" }],
    userId: [{ required: true, message: "用户id不能为空", trigger: "blur" }],
    type: [{ required: true, message: "事件类型不能为空", trigger: "change" }],
    startDate: [
      { required: true, message: "触发时间不能为空", trigger: "blur" },
    ],
    eventValue: [
      { required: true, message: "事件产物,记录值不能为空", trigger: "blur" },
    ],
  },
});

const { queryParams, form, rules } = toRefs(data);

/** 查询用户触发事件记录列表 */
function getList() {
  loading.value = true;
  getBuildStatistics(queryParams.value).then((response) => {
    console.log(response);
    allVisiteData.value = response.data;
    loading.value = false;
  });
}
// 查询运营数据汇总
// function getAllData() {
//   loading.value = true;
//   dailyOperatingResultsApi().then((response) => {
//     console.log(response);
//     allVisiteData.value = response.data;
//     loading.value = false;
//   });
// }

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    userId: null,
    type: null,
    startDate: null,
    endDate: null,
    nickName: null,
    salesDirector: null,
    eventValue: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
  };
  proxy.resetForm("hairTriggerEventRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");

  queryParams.value = {
    pageNum: 1,
    pageSize: 15,
    userId: null,
    type: null,
    startDate: null,
    endDate: null,
    nickName: null,
    salesDirector: null,
    eventValue: null,
    theirMilitary: null,
  };
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download(
    "/business/operation/exportActivityUserStatistics",
    {
      ...queryParams.value,
    },
    `hairTriggerEvent_${new Date().getTime()}.xlsx`
  );
}
// getAllData();
getList();
</script>
